package 剑指offer.Month7_07.day16;

public class 把数字翻译成字符串 {
    public int solve(String nums) {
        // write code here
        if (nums == null || nums.length() == 0) {
            return 0;
        }
        int a = 1;
        int b = 1;
        int sum = 1;
        for (int i = 1; i < nums.length(); i++) {
            int value = getValue(nums.charAt(i - 1),nums.charAt(i));

            if(nums.charAt(i) == '0'){
                b = 0;
            }
            if(value >= 10 && value <= 26){
                sum = a + b;
            }else{
                sum = b;
            }
            a = b;
            b = sum;
        }
        return sum;
    }

    public int getValue(char a,char b){
        return Integer.parseInt("" +a + b);
    }
}
